//
//  viewView.m
//  霓虹灯
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "viewView.h"

#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height


@implementation viewView

- (void)dealloc{
    
    [_view1 release];
    [_view2 release];
    [_view3 release];
    [_view4 release];
    [_view5 release];
    [super dealloc];
    
}

// 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self doIt];
    }
    
    return self;
}

#pragma mark : 创建霓虹灯的5个view  或 for 循环创建8个

- (void)doIt{
    // 个人认为for循环比 下边的创建5个view low, 除非有特殊需要, 改变随机色的范围,使其组成的颜色基本为鲜艳的颜色
    for (NSInteger i = 0; i < 9; i++) {
        UIView *view = [[UIView alloc] init];
       view.frame = CGRectMake(60 + i * 20 , 120 + i * 20 , 280 - i * 40 , 280 - i * 40);
        NSLog(@"%f",ScreenWidth);
        view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1];
        view.tag = 10000 + i;
        [self addSubview:view];
        [view release];
    }
/*
#pragma mark 创建五个view
#if 0
    self.view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];
    self.view1.backgroundColor = [UIColor redColor];
    [self addSubview:self.view1];
    [_view1 release];
    self.view2 = [[UIView alloc]initWithFrame:CGRectMake(85, 85, 300 - 75, 300 - 75)];
    self.view2.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.view2];
    [_view2 release];
    
    
    self.view3 = [[UIView alloc]initWithFrame:CGRectMake(108, 108, 300 - 125, 300 - 125)];
    self.view3.backgroundColor = [UIColor blueColor];
    [self addSubview:self.view3];
    [_view3 release];
    
    
    self.view4 = [[UIView alloc]initWithFrame:CGRectMake(130, 130, 300 - 175, 300 - 175)];
    self.view4.backgroundColor = [UIColor cyanColor];
   [self addSubview:self.view4];
    [_view4 release];
    
    
    self.view5 = [[UIView alloc]initWithFrame:CGRectMake(155, 155, 300 - 225, 300 - 225)];
    self.view5.backgroundColor = [UIColor greenColor];
    [self addSubview:self.view5];
    [_view5 release];
#endif*/
    // 创建定时器
    [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(viewAction:) userInfo:nil repeats:YES];
 
}


#pragma mark : 重复循环的方法
- (void)viewAction:(UIView *)view{
    
//    UIView *newView = [[UIView alloc] init];
//    newView.backgroundColor = self.view1.backgroundColor;
//    
//    self.view1.backgroundColor = self.view2.backgroundColor;
//    self.view2.backgroundColor = self.view3.backgroundColor;
//    self.view3.backgroundColor = self.view4.backgroundColor;
//    self.view4.backgroundColor = self.view5.backgroundColor;
//    self.view5.backgroundColor = newView.backgroundColor;
//    [newView release];

    
    
    [self viewWithTag:10000].backgroundColor = [self viewWithTag:10001].backgroundColor;
    [self viewWithTag:10001].backgroundColor = [self viewWithTag:10002].backgroundColor;
    [self viewWithTag:10002].backgroundColor = [self viewWithTag:10003].backgroundColor;
    [self viewWithTag:10003].backgroundColor = [self viewWithTag:10004].backgroundColor;
    [self viewWithTag:10004].backgroundColor = [self viewWithTag:10005].backgroundColor;
    [self viewWithTag:10005].backgroundColor = [self viewWithTag:10006].backgroundColor;
    [self viewWithTag:10006].backgroundColor = [self viewWithTag:10007].backgroundColor;
    [self viewWithTag:10007].backgroundColor = [self viewWithTag:10008].backgroundColor;
    [self viewWithTag:10008].backgroundColor = [self viewWithTag:10000].backgroundColor;
    

}











@end
